package com.hainatong.shiphelper.module.warehouse.adapter;

import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat;
import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.ItemLinyongGoodsViewBinding;
import com.hainatong.shiphelper.module.warehouse.entity.LinYongInfoBean;
import org.jetbrains.annotations.NotNull;

public class EquipmentRecordAdapter extends BaseQuickAdapter<LinYongInfoBean, BaseDataBindingHolder<ItemLinyongGoodsViewBinding>>
{
    public EquipmentRecordAdapter()
    {
        super(R.layout.item_linyong_goods_view);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemLinyongGoodsViewBinding> bindingHolder, LinYongInfoBean recordBean)
    {
        ItemLinyongGoodsViewBinding binding = bindingHolder.getDataBinding();
        if( binding != null )
        {
            Drawable pointBg = ContextCompat.getDrawable(getContext(),R.drawable.shape_oval );

            // status  1 使用中,2已归还,3部分归还
            String statusStr = recordBean.getStatus();
            int statu = StringUtils.isEmpty(statusStr)? 1: Integer.valueOf( statusStr );
            switch (statu)
            {
                case 1:
                    pointBg.setColorFilter( ContextCompat.getColor(getContext() ,R.color.green_point ) , PorterDuff.Mode.SRC_ATOP );
                    binding.pointTag.setBackground( pointBg );
                    binding.tvStatus.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_green_tv_bg_r5 ) );
                    binding.tvStatus.setText("使用中");
                    binding.tvStatus.setTextColor( ContextCompat.getColor(getContext() ,R.color.green_point ));
                    break;
                case 2:
                    pointBg.setColorFilter( ContextCompat.getColor(getContext() ,R.color.oval_gary ) , PorterDuff.Mode.SRC_ATOP );
                    binding.pointTag.setBackground( pointBg );
                    binding.tvStatus.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_gray_tv_bg_r5 ) );
                    binding.tvStatus.setText("已归还");
                    binding.tvStatus.setTextColor( ContextCompat.getColor(getContext() ,R.color.tips_gray_text ));
                break;
                case 3:
                    pointBg.setColorFilter( ContextCompat.getColor(getContext() ,R.color.blue ) , PorterDuff.Mode.SRC_ATOP );
                    binding.pointTag.setBackground( pointBg );
                    binding.tvStatus.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_blue_tv_bg_r5 )  );
                    binding.tvStatus.setText("部分归还");
                    binding.tvStatus.setTextColor( ContextCompat.getColor(getContext() ,R.color.blue ));
                    break;
                case 4:
                    binding.pointTag.setBackground( pointBg );
                    binding.tvStatus.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.shape_red_tv_bg_r5 ) );
                    binding.tvStatus.setText("已报废");
                    binding.tvStatus.setTextColor( ContextCompat.getColor(getContext() ,R.color.red_oval ));
                break;
            }


            binding.setRecordBean( recordBean );
            binding.executePendingBindings();
        }
    }
}
